{extend name="common/base" /}
{block name="body"}
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-form-item">
                <label class="layui-form-label">角色名：</label>
                <div class="layui-input-inline">
                    <input name="role_name" required="" lay-verify="required" placeholder="请输入登录账户" autocomplete="off" value="{$role.role_name}" class="layui-input" type="text">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">公众号权限</label>
                <div class="layui-input-block ">
                    <div class="select-allmp">
                        <input type="checkbox"  title="全选公众号" lay-skin="primary" lay-filter="allChoose" id="selectAllMp">
                    </div>

                    {volist name="mpList" id="mp"}
                    <div class="select-mplist {if condition='$mp.checked == 1'}on{/if} ">

                        <div class="logo-left">
                            <img src="{$mp.logo}">
                        </div>
                        <div class="logo-right" style="width: 112px;overflow: hidden;">
                            <p class="p1">{$mp.name}</p>
                            <p class="p2">类型：{$mp.type_name}</p>
                        </div>
                        <input type="checkbox" name="mp_power[{$mp.id}]" class="select-mp" value="{$mp.id}" {if condition="$mp.checked == 1"}checked{/if} lay-ignore>
                    </div>
                    {/volist}
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">菜单权限</label>
                <div class="layui-input-block ">
                    <div class="select-allmp">
                        <input type="checkbox"  title="全选菜单" lay-skin="primary" lay-filter="allChooseMenu" id="selectAllMenu">
                    </div>

                    <div class="layui-row">
                        {volist name="menuList" id="v"}
                        <div >
                            <!--<div class="layui-col-md6">-->
                            <input type="checkbox" name="mp_menu[{$v.id}]"  lay-filter="chooseMenu" id="mp_menu{$v.id}" {if condition="$v.checked == 1"}checked{/if} class="select-menu" value="{$v.id}" lay-skin="primary" title="{$v.name}">
                            {if condition='$v.id != 61'}
                            {volist name="v.child" id="v"}
                            <div style="padding-left: 50px;" class="child-menu">
                                <input type="checkbox" name="mp_menu[{$v.id}]"  lay-filter="chooseMenu" id="mp_menu{$v.id}" {if condition="$v.checked == 1"}checked{/if} class="select-menu" value="{$v.id}" lay-skin="primary" title="{$v.name}">
                                {volist name="v.child" id="v"}
                                <div style="padding-left: 50px;" class="child-menu">
                                    <input type="checkbox" name="mp_menu[{$v.id}]"  lay-filter="chooseMenu" id="mp_menu{$v.id}" {if condition="$v.checked == 1"}checked{/if} class="select-menu" value="{$v.id}" lay-skin="primary" title="{$v.name}">

                                    {volist name="v.child" id="v"}
                                    <div style="padding-left: 50px;" class="child-menu">
                                        <input type="checkbox" name="mp_menu[{$v.id}]"  lay-filter="chooseMenu" id="mp_menu{$v.id}" {if condition="$v.checked == 1"}checked{/if} class="select-menu" value="{$v.id}" lay-skin="primary" title="{$v.name}">
                                    </div>
                                    {/volist}
                                </div>
                                {/volist}
                            </div>

                            {/volist}
                            {/if}
                        </div>


                        <div style="height: 2px;margin: 10px 0;background: #cccccc;"></div>
                        {/volist}
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="updatepwd">确认更改</button>
            </div>
        </div>
    </div>
</form>
<script>

    layui.use('form', function(){
        var $ = layui.jquery, form = layui.form;

        //全选

    });
    layui.use('form', function () {
        var form = layui.form;
        form.on('submit(updatepwd)', function (data) {
            $.post('',data.field,function (res) {
                if(res.status=='0'){
                    layer.msg(res.msg);
                }else if(res.status=='1'){
                    layer.msg(res.msg,{time:1000},function () {
                        location.href="{:url('adminrole')}";
                    });
                }
            })
            return false;
        });
        form.on('checkbox(allChooseMenu)', function(data){

            if($(data.elem).prop("checked")) {
                $('.select-menu').prop('checked', true);
            }else{
                $('.select-menu').prop('checked',false);
            }
            form.render('checkbox');
        });
        form.on('checkbox(chooseMenu)', function(data){
            if($(data.elem).prop("checked")) {
                $(data.elem).nextAll('.child-menu').find('input').prop('checked','checked');
                $(data.elem).parents('.child-menu').prevAll('input').prop('checked','checked');
            }else{
                $(data.elem).nextAll('.child-menu').find('input').prop('checked',false);
            }
            form.render('checkbox');
        });

        form.on('checkbox(allChoose)', function(data){

            if($(data.elem).prop("checked")) {

                $('.select-mplist').addClass('on');
                $('.select-mp').prop('checked', true);

            }else{
                $('.select-mplist').removeClass('on');
                $('.select-mp').prop('checked',false);
            }
            form.render('checkbox');
        });
        $(function () {
            $('.select-mp').change(function () {
                if($(this).prop("checked")){
                    $(this).parent('.select-mplist').addClass('on');
                }else{
                    $(this).parent('.select-mplist').removeClass('on');
                }
            });

        })
    });
    
</script>
{/block}